package com.codeavatar.catools.helper;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.Toast;

import com.google.android.material.snackbar.Snackbar;

/**
 * +----------------------------------------------------------------------
 * | @Author: codeavatar   @Year：2022
 * +----------------------------------------------------------------------
 * | @Email: codeavatar@aliyun.com
 * +----------------------------------------------------------------------
 **/
public class CaSnackbarHelper {
    private final String TAG = this.getClass().getSimpleName();

    private static View gView;
    private Snackbar gSnackbar = null;

    //++++++++++++++++++++++++++++++++++++++
    //++ 外部方法
    //++++++++++++++++++++++++++++++++++++++

    public void nackbar(String message){
        this.snackbarFilter();
        this.gSnackbar = Snackbar.make(gView,message,Snackbar.LENGTH_LONG);
        this.gSnackbar.setAction("",null);
        this.gSnackbar.show();
    }

    public void nackbar(String ... str) {
        this.snackbarFilter();
        StringBuilder sb = new StringBuilder("");
        for (String item : str) {
            sb.append(item).append("\n");
        }
        if (sb.length() > 0) {
            sb.deleteCharAt(sb.length() - 1);
        }
        this.gSnackbar = Snackbar.make(gView,sb.toString(), Snackbar.LENGTH_LONG);
        this.gSnackbar.show();
    }

    public void nackbar(String message,int gravity){
        this.snackbarFilter();
        this.gSnackbar = Snackbar.make(gView,message, Snackbar.LENGTH_LONG);
        this.gSnackbar.show();
    }

    private static CaSnackbarHelper init;
    public static CaSnackbarHelper init(View view){
        gView = view;
        if(null == init){
            init = new CaSnackbarHelper();
        }
        return init;
    }

    //++++++++++++++++++++++++++++++++++++++
    //++ 内部方法
    //++++++++++++++++++++++++++++++++++++++

    private void snackbarFilter(){
        if(null != gSnackbar){
            gSnackbar.dismiss();
        }
    }

    //++++++++++++++++++++++++++++++++++++++
    //++ 内部方法
    //++++++++++++++++++++++++++++++++++++++

    private CaSnackbarHelper(){
//        throw new UnsupportedOperationException("Initialization is not supported");
    }
}
